package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingGradeDto;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingGradeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/nursingLevel")
@Api(tags = "护理等级管理")
@Slf4j
public class NursingGradeController extends BaseController{

    @Autowired
    NursingGradeService nursingGradeService;

    @GetMapping("/listAll")
    @ApiOperation(value = "获取所有护理等级", notes = "无需参数，获取所有护理等级，返回护理等级列表")
    public ResponseResult<List<NursingGradeVo>> listAll() {
        List<NursingGradeVo> nursingGradeVos = nursingGradeService.listAll();
        return success(nursingGradeVos);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级", notes = "新增护理等级")
    public ResponseResult insert(@RequestBody NursingGradeDto nursingGradeDto) {
        nursingGradeService.insert(nursingGradeDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "5", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "等级名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "等级状态", dataType = "int", paramType = "query")
    })
    public ResponseResult<PageResponse<NursingGradeVo>> queryByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {
        log.info("护理等级分页请求信息：{}，{}，{}，{}", pageNum, pageSize, name, status);
        PageResponse<NursingGradeVo> byPage = nursingGradeService.findByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(byPage);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理等级信息")
    public ResponseResult<NursingGradeVo> queryById(@PathVariable Long id) {
        NursingGradeVo nursingGradeVo = nursingGradeService.queryById(id);
        return success(nursingGradeVo);
    }


    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级", notes = "修改护理等级")
    public ResponseResult update(@RequestBody NursingGradeDto nursingGradeDto) {
        nursingGradeService.update(nursingGradeDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级", notes = "根据ID删除护理等级")
    public ResponseResult delete(@PathVariable Long id) {
        nursingGradeService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "项目ID", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "项目状态", required = true, dataType = "int", paramType = "path")
    })
    public ResponseResult updateProjectStatus(@PathVariable(value = "id") Long id, @PathVariable(value = "status") Integer status) {
        nursingGradeService.updateProjectStatus(id, status);
        return success();
    }

}
